home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / DMAKE38B.ARJ / M_INIT.C < prev    next >
C/C++ Source or Header  |  1992-01-23  |  2KB  |  104 lines

  1. /*
  2.  * (c) Copyright 1990 Conor P. Cahill (uunet!virtech!cpcahil).  
  3.  * You may copy, distribute, and use this software as long as this
  4.  * copyright statement is not removed.
  5.  */
  6. #include <stdio.h>
  7. #include "malloc.h"
  8.  
  9. /*
  10.  * Function:    malloc_init()
  11.  *
  12.  * Purpose:    to initialize the pointers and variables use by the
  13.  *        malloc() debugging library
  14.  *
  15.  * Arguments:    none
  16.  *
  17.  * Returns:    nothing of any value
  18.  *
  19.  * Narrative:    Just initialize all the needed variables.  Use mallopt
  20.  *        to set options taken from the environment.
  21.  *
  22.  */
  23. #ifndef lint
  24. static
  25. char rcs_hdr[] = "$Id: m_init.c,v 1.1 1992/01/24 03:29:03 dvadura Exp $";
  26. #endif
  27.  
  28. void
  29. malloc_init()
  30. {
  31.     char            * cptr;
  32.     char            * getenv();
  33.     union malloptarg      m;
  34.     extern char        * malloc_data_end;
  35.     extern char        * malloc_data_start;
  36.     extern struct mlist    * malloc_end;
  37.     extern struct mlist      malloc_start;
  38.     char            * sbrk();
  39.  
  40.     /*
  41.       * If already initialized...
  42.      */
  43.     if( malloc_data_start != (char *) 0)
  44.     {
  45.         return;
  46.     }
  47.  
  48.  
  49.     malloc_data_start = sbrk(0);
  50.     malloc_data_end = malloc_data_start;
  51.     malloc_start.s.size = 0;
  52.     malloc_end = &malloc_start;
  53.     
  54.     if( (cptr=getenv("MALLOC_WARN")) != NULL )
  55.     {
  56.         m.i = atoi(cptr);
  57.         (void) mallopt(MALLOC_WARN,m);
  58.     }
  59.  
  60.     if( (cptr=getenv("MALLOC_FATAL")) != NULL)
  61.     {
  62.         m.i = atoi(cptr);
  63.         (void) mallopt(MALLOC_FATAL,m);
  64.     }
  65.  
  66.     if( (cptr=getenv("MALLOC_CKCHAIN")) != NULL)
  67.     {
  68.         m.i = atoi(cptr);
  69.         (void) mallopt(MALLOC_CKCHAIN,m);
  70.     }
  71.  
  72.     if( (cptr=getenv("MALLOC_ERRFILE")) != NULL)
  73.     {
  74.         m.str = cptr;
  75.         (void) mallopt(MALLOC_ERRFILE,m);
  76.     }
  77.  
  78. }
  79.  
  80. /*
  81.  * $Log: m_init.c,v $
  82.  * Revision 1.1  1992/01/24  03:29:03  dvadura
  83.  * dmake Version 3.8, Initial revision
  84.  *
  85.  * Revision 1.6  90/08/29  22:23:21  cpcahil
  86.  * fixed mallopt to use a union as an argument.
  87.  * 
  88.  * Revision 1.5  90/08/29  21:22:50  cpcahil
  89.  * miscellaneous lint fixes
  90.  * 
  91.  * Revision 1.4  90/05/11  15:53:35  cpcahil
  92.  * fixed bug in initialization code.
  93.  * 
  94.  * Revision 1.3  90/05/11  00:13:08  cpcahil
  95.  * added copyright statment
  96.  * 
  97.  * Revision 1.2  90/02/24  21:50:20  cpcahil
  98.  * lots of lint fixes
  99.  * 
  100.  * Revision 1.1  90/02/24  17:10:53  cpcahil
  101.  * Initial revision
  102.  * 
  103.  */
  104.